package com.axonactive.training.dao;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.axonactive.training.model.Category;

@Stateless
public class CategoryDao {
	@PersistenceContext
	private EntityManager em;
	
	public void saveCategory(Category category){
		em.persist(category);
	}
	
	public Category getCategoryById(Long id){
		return em.createQuery("select c from Category c where c.id = :id", Category.class)
					.setParameter("id", id).getSingleResult();
	}
	
	public List<Category> getCategoryList(){
		return em.createQuery("select c from Category c", Category.class).getResultList();		
	}
}
